package com.bjlytr.license.client.util;

import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;

import java.io.*;

/**
 * @author Ledison
 * @date 2021/9/17
 */
public class FileUtil {
    public static void toFile(InputStream in, final File file) {
        try {
            OutputStream out = new FileOutputStream(file);
            Throwable var3 = null;

            try {
                copy(in, out);
            } catch (Throwable var13) {
                var3 = var13;
                throw var13;
            } finally {
                if (out != null) {
                    if (var3 != null) {
                        try {
                            out.close();
                        } catch (Throwable var12) {
                            var3.addSuppressed(var12);
                        }
                    } else {
                        out.close();
                    }
                }

            }

        } catch (IOException var15) {
            throw new RuntimeException(var15);
        }
    }

    public static int copy(InputStream in, OutputStream out) throws IOException {
        Assert.notNull(in, "No InputStream specified");
        Assert.notNull(out, "No OutputStream specified");

        int var2;
        try {
            var2 = StreamUtils.copy(in, out);
        } finally {
            try {
                in.close();
            } catch (IOException var12) {
            }

            try {
                out.close();
            } catch (IOException var11) {
            }

        }

        return var2;
    }
}
